package myStack;
import java.util.Arrays;

public class MyStack {
    int[] data;
    int top = -1;

    public MyStack() {
        data = new int[3];
    }

    //栈是否为空
    public boolean isEmpty() {
        return top == -1;
    }

    public void push(int data) {
        if (this.top == this.data.length - 1) {
            this.data = Arrays.copyOf(this.data,2 * this.data.length);
        }
        this.data[++top] = data;
    }

    //出栈
    public int pop() {
        if (isEmpty()) {
            throw new RuntimeException("栈空！");
        }
        return data[top--];
    }

    public int peek() {
        if (isEmpty()) {
            throw new RuntimeException("栈空！");
        }
        return data[top];
    }
}
